package cn.sue.example.three;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class MainActivity extends AppCompatActivity  implements View.OnClickListener {

    private EditText user;
    private EditText password;
    private Button login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ininView();


        Map<String, String> userInfo = saveUser.getUserInfo(this);
        if(userInfo!=null){
            user.setText(userInfo.get("user"));
            password.setText(userInfo.get("password"));
            Toast.makeText(this,"sucessfuly",Toast.LENGTH_LONG);
        }


    }

    private void ininView() {
        user = findViewById(R.id.input_one);
        password = findViewById(R.id.input_two);
        login = findViewById(R.id.btn);
        login.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        String  number=user.getText().toString().trim();
        String  Password=password.getText().toString().trim();
        if(TextUtils.isEmpty(number)||TextUtils.isEmpty(Password)){
            Toast.makeText(this,"账号或密码为空",Toast.LENGTH_LONG).show();
            return;
        }
          Toast.makeText(this,"登录成功",Toast.LENGTH_LONG).show();
        boolean isSave = saveUser.saveUserInfo(this, number, Password);

        if(isSave){
            Toast.makeText(this,"保存成功",Toast.LENGTH_LONG).show();
        }


    }
}
